class LastfmService {

    boolean transactional = false

    static scope = "singleton" //needs to be in a singleton scope due to the use in a filter <DefaultFilters.groovy>

    def recentTracks(String username) {
        def endPoint = "http://ws.audioscrobbler.com/1.0/user/${username}/recenttracks.xml";

        try {
            def stream = new URL(endPoint).openStream();

            def recenttracks = new XmlSlurper().parse(stream);
            return recenttracks;
        }
        catch (Exception e) {
            log.warn("Could not retrieve last.fm data. Reason ${e.message}")
            return 'not available';
        }

    }
}
